<!-- kform -->
<template>
  <form>
    <slot></slot>
  </form>
</template>

<script>
export default {
  data() {
    return {};
  },
  provide() {
    return {
      form: this
    };
  },
  props: ["model", "rules"],
  components: {},

  computed: {},

  mounted() {},

  methods: {
    async validate(cb) {
      const tasks = this.$children
        .filter(v => v.prop)
        .map(item => item.validate());
      console.log(tasks);
      const results = await Promise.all(tasks);
      console.log(results);
      let ret = true;
      results.forEach(valid => {
        if (!valid) {
          ret = false; // 只要一个失败就失败
        }
      });
      cb(ret)
    }
  }
};
</script>
<style scoped>
</style>